<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理项目</title>
    <meta name="renderer" content="webkit">
    <#--   <link rel="stylesheet" href="${re.contextPath}/plugin/lay/layui/css/layui.css">-->
    <!--layui样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--layui-dropdown-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/layui/dropdown_2.3.3/dropdown.css">
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--扩展样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/extended.css">
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <!-- 公共配置第三方组件 -->
    <script type="text/javascript">
        layui.config({
            version: false,
            debug: false,
            base: "${re.contextPath}/plugin/layui/dropdown_2.3.3/"
        })
    </script>
    <style>
        .select ul li:nth-child(4)>.ml10,
        .select ul li:nth-child(5)>.ml10{
            margin-left: 5px;
        }
        .select ul li:nth-child(4) .money{
            width: 90%;
        }
        .select ul li:nth-child(5) .money{
            width: 71%;
        }
        .select ul li:nth-child(4)>div{
            width: 77%;
        }
        .select ul li:nth-child(4) .money>div{
            width: 48%;
        }
        .select ul li:nth-child(5) .money>div{
            width: 43%;
        }
        .select ul li:nth-child(4) .money>div input{
            width: 95%;
        }
        .select ul li:nth-child(5) .money>div input{
            width: 60%;
        }
        .layu-menu-item-wrap{
            float:none!important;
            width: 100% !important;
        }
        .screening ul li input {
            width: 65%;
            padding-left: 5%;
            border: 0;
        }

        .screening ul li>select {
            border: 1px solid #DDDDDD;
        }

        .screening .money div {
            border: 1px solid #DDDDDD;
        }
    </style>
</head>
<body>
<div class="screening whitebg clearfix">
    <div class="select">
        <ul class="clearfix">
            <li>
                <span>项目状态</span>
                <select id="status">
                    <option value="">请选择</option>
                    <#list prostatus as vo>
                        <option value="${vo.badtCode}">${vo.badtName}</option>
                    </#list>
                </select>
            </li>
            <li>
                <span>实施地点</span>
                <select name="province" id="province" onchange="getCity()">
                    <option value="">请选择</option>
                    <#list provincelist as vo>
                        <option value="${vo.code}">${vo.name}</option>
                    </#list>
                </select>
                <select name="city" id="city" lay-filter="city" lay-verify="required"
                        style="width:30% !important;">
                    <option value="">请选择</option>
                    <#--   <#list citylist as vo>
                           <option value="${vo.code}">${vo.name}</option>
                       </#list>-->
                </select>
            </li>
            <li>
                <span>行业</span>
                <select id="hyType">
                    <option value="">请选择</option>
                    <#list hystatus as vo>
                        <option value="${vo.badtCode}">${vo.badtName}</option>
                    </#list>
                </select>
            </li>
            <li>
                <span class="fl">项目时间</span>
                <div class="clearfix fl ml10">
                    <div class="money clearfix">
                        <div class="fl">
                            <#assign currentUser = Session["currentPrincipal"]>
                            <input type="text" id="totalDurationBeginDate" autocomplete="off" placeholder="起始时间">
                        </div>
                        <div class="fr">
                            <input type="text" id="totalDurationEndDate" autocomplete="off" placeholder="终止时间">
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <span class="fl">合同额</span>
                <div class="money clearfix fl ml10">
                    <div class="fl">
                        <input type="text" id="htMoneyMin">
                        <span>元</span>
                    </div>
                    <span class="fl">-</span>
                    <div class="fr">
                        <input type="text" id="htMoneyMax">
                        <span>元</span>
                    </div>
                </div>
            </li>
            <li>
                <span>项目归属</span>
                <select id="projectOwner">
                    <option value="">请选择</option>
                    <#list ownerCompanyList as vo>
                        <option value="${vo.bcId}">${vo.bcName}</option>
                    </#list>
                </select>
            </li>
            <li>
                <span>项目名称</span>
                <input type="text" style="border:1px solid #DDDDDD;" name="projectName" id="projectName" placeholder="请输入项目名称">
            </li>
            <li>
                <span>内部编号</span>
                <input type="text" style="border:1px solid #DDDDDD;" name="insideContractNo" id="insideContractNo" placeholder="请输入内部编号">
            </li>
        </ul>
        <div class=" project" style="margin-top: 0px;width: 100%;padding-left: 0px;">
            <div class="fl clearfix">
                <@shiro.hasPermission name="mgr:acc">
                    <a href="#" class="fr white ft14 btn_my" onclick="viewAc()">查看账号信息</a>
                </@shiro.hasPermission>
                <@shiro.hasPermission name="mgr:rec">
                    <a href="#" class="fr white ft14" onclick="viewHs()">项目回收站</a>
                </@shiro.hasPermission>
                <@shiro.hasPermission name="mgr:bdel">
                    <a href="#" class="fr white ft14 btn_del" onclick="deleteHs()">批量删除</a>
                </@shiro.hasPermission>
                <a href="#" class="fr white ft14 btn_my" onclick="query(1)">我的项目</a>
            </div>
            <div class="fr clearfix">
                <a href="#" class="fr white ft14 btn_my" onclick="query()">筛选</a>
                <a href="#" class="fr white ft14 btn_del" onclick="reset()">重置</a>
            </div>
        </div>
        <div class="project whitebg" style="width: 100%;padding-left: 0px;margin-top: 0px;padding-top: 10px;margin-right: 0px;padding-right: 0px;">
            <table id="projectList" class="layui-hide" lay-filter="project"></table>
        </div>
    </div>
</div>

<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script type="text/html" id="toolBar">
    <@shiro.hasPermission name="mgr:view">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" style="margin-left: 0px;">查看</a>
    </@shiro.hasPermission>
    <@shiro.hasPermission name="mgr:show">
        {{#  if('${currentUser.tags}'.indexOf(d.id+':'+d.projectName+';')==-1){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="show" style="margin-left: 0px;">显示</a>
        {{#  } else{ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="noshow" style="margin-left: 0px;">取消</a>
        {{#  } }}
    </@shiro.hasPermission>
    <@shiro.hasPermission name="mgr:edit">
        {{#  if(d.status != '001'){ }}
        <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="edit" style="margin-left: 0px;">编辑</a>
        {{#  } }}
    </@shiro.hasPermission>
    <#assign currentUser = Session["currentPrincipal"]>
    {{#  if(  ((d.projectManagerPerson)&&(d.projectManagerPerson=='${currentUser.id}'))  || (d.supervisorEngineer=='${currentUser.id}')){ }}
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="info" style="margin-left: 0px;">基本信息</a>
    {{#  } }}


    {{#  if(  ((d.projectManagerPerson)  &&  (d.projectManagerPerson=='${currentUser.id}'))  &&  (d.supervisorEngineer=='${currentUser.id}')  ){ }}
    <a id="more-btn-{{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs more-btn ml0" lay-filter="more-btn-{{d.id}}"
       lay-dropdown="{align:'center', menus: [{txt: '导出', event:'export'}, {txt: '删除', event:'del'}, {txt: '修改记录', event:'modrecord'}]}">更多操作</a>
    {{# }else{ }}
        {{#  if(  ((d.projectManagerPerson)  &&  (d.projectManagerPerson=='${currentUser.id}'))  &&  (d.supervisorEngineer!='${currentUser.id}')  ){ }}
        <a id="more-btn-{{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs more-btn ml0" lay-filter="more-btn-{{d.id}}"
           lay-dropdown="{align:'center', menus: [{txt: '导出', event:'export'},{txt: '删除', event:'del'},{txt: '修改记录', event:'modrecord'}]}">更多操作</a>
        {{# }else{ }}
            {{#  if(  ((d.projectManagerPerson)  &&  (d.projectManagerPerson!='${currentUser.id}'))  &&  (d.supervisorEngineer=='${currentUser.id}')  ){ }}
            <a id="more-btn-{{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs more-btn ml0" lay-filter="more-btn-{{d.id}}"
               lay-dropdown="{align:'center', menus: [{txt: '修改记录', event:'modrecord'}]}">更多操作</a>
            {{# }else{ }}
                {{#  if(  ((d.projectManagerPerson)  &&  (d.projectManagerPerson!='${currentUser.id}'))  &&  ('${gcbjl}'=='1')  ){ }}
                <a id="more-btn-{{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs more-btn ml0" lay-filter="more-btn-{{d.id}}"
                   lay-dropdown="{align:'center', menus: [{txt: '修改记录', event:'modrecord'}]}">更多操作</a>
                {{# }else{ }}
                {{#  } }}
            {{#  } }}
        {{#  } }}
    {{#  } }}
</script>
<script>
    var layer;
    var form = layui.form;
    var table = null;
    var tableIns = null;
    document.onkeydown = function (e) { // 回车提交表单
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code == 13) {
            $(".select .select-on").click();
        }
    }

    //注意进度条依赖 element 模块，否则无法进行正常渲染和功能性操作
    var element,dropdown;
    layui.use(['element','dropdown'], function () {
        element = layui.element , dropdown = layui.dropdown;
    });

    var tableCols =  [[
        {checkbox: true, fixed: true, width: '5%'},
        {
            field: 'status', title: '项目状态', width: '10%', sort: true, templet: function (d) {

                if (d.status == "000") {
                    return '<span class="pro_status" style="background-color:#8d0517;">已删除 </span>'
                }
                if (d.status == "001") {
                    return '<span class="pro_status" style="background-color:#aa9898;">未提交</span>'
                }
                if (d.status == "002") {
                    return '<span class="pro_status" style="background-color:#928c8c;">未启动</span>'
                }
                if (d.status == "004") {
                    return '<span class="pro_status" style="background-color:#569e20;">进行中</span>'
                }
                if (d.status == "003") {
                    return '<span class="pro_status" style="background-color:#2161e3;">已完成</span>'
                }
                if (d.status == "005") {
                    return '<span class="pro_status" style="background-color:#E80C0C;">已延期</span>'
                }
            }
        },
        {
            title: '序号', width: '5%', templet: function (res) {
                return res.LAY_INDEX;
            }
        },
        {
            field: 'projectName', title: '项目名称', width: '20%', sort: true, templet: function (d) {
                return '<span class="cursor" onclick="showDetail(\'' + d.id + '\',\'' + d.projectName + '\')">' + d.projectName + '</span>';
            }
        },
        {field: 'insideContractNo', title: '内部编号', width: '10%', sort: false},
        {
            field: 'checkShape', title: '监理形式', width: '10%', sort: true, templet: function (d) {

                if (d.checkShape == "001") {
                    return '阶段式监理';
                }
                if (d.checkShape == "002") {
                    return '全过程监理';
                }
                if (d.checkShape == "003") {
                    return '驻场式监理';
                }
                if (d.checkShape == "004") {
                    return '验收式监理';
                }
                if (d.checkShape == "" || d.checkShape == null || d.checkShape == undefined ) {
                    return '';
                }
            }
        },
        {
            field: 'progress', title: '项目进度', width: '15%', sort: true, templet: function (d) {
                var prog = d.progress;
                if(prog){
                    prog = parseFloat(prog).toFixed(2);
                }
                return '<div class="layui-progress layui-progress-big" lay-showpercent="true">' +
                    '<div class="layui-progress-bar" lay-percent="' + prog + '%"></div>' +
                    '</div>';
            }
        },
        {field: 'remark', title: '操作', width: '27%', toolbar: "#toolBar"}
     ]];
    layui.use('table', function () {
        table = layui.table;
        element = element;
        //方法级渲染
        tableIns = table.render({
            id: 'projectList',
            elem: '#projectList',
            autoSort: false,
            height: "auto",
            url: '/supervisor/projectManager/showProjectList',
            cols:tableCols,
            page: true,
            done: function (res, currentCount) {
                console.log("done......")
                element.render();
                $(".layui-table-page select").css("width","80px");
                var  progressbar =$(".layui-table-main").find(".layui-progress-bar");
                $(progressbar).each(function (i, v) {
                    var percent = $(v).attr("lay-percent");
                    if(percent){
                       var per= percent.replace("%","");
                        if(parseFloat(per)<5  && parseFloat(per)>0){
                            $(v).css("width","5%");
                        }
                    }
                });
                dropdown.suite();
                //如果页面缓存中有需要跳转的页面,跳转页面,用户监理系统外打开项目查看页面
                openProjInfo();
            }
        });
        //监听工具条
        table.on('tool(project)', function (obj) {
            var data = obj.data;
            var that=$(this);
            if (obj.event === 'detail') {
                window.parent._showtab('xm_v' + data.id, '查看-' + data.projectName, '/supervisor/projectManager/projectDetail?type=v&id=' + data.id);
            } else if (obj.event === 'show') {
                layerAjaxGet('/user/newtag', {pTagId: data.id, pTagName: data.projectName}, null, function (d) {
                    if (d.flag) {
                        parent.layer.msg(d.msg, {icon: 1});
                        that.html("取消").attr("lay-event","noshow");
                        window.parent._showtab('xm_v' + data.id, '查看-' + data.projectName, '/supervisor/projectManager/projectDetail?type=v&id=' + data.id);
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            } else if (obj.event === 'noshow') {
                layerAjaxGet('/user/deltag', {pTagId: data.id}, null, function (d) {
                    if (d.flag) {
                        that.html("显示").attr("lay-event","show");
                        layer.msg(d.msg, {icon: 1});
                    } else {
                        layer.msg(d.msg, {icon: 2});
                    }
                });
            } else if (obj.event === 'edit') {
                var  status=data.status;
                if("001"==status){
                    layer.msg('未提交状态不能编辑。', {icon: 2});
                    return ;
                }
                window.parent._showtab('xm_e' + data.id, '编辑-' + data.projectName, '/supervisor/projectManager/projectDetail?type=m&id=' + data.id);
            } else if (obj.event === 'del') {
                deleteItem(data.id,data.projectName);
            } else if (obj.event === 'info') {
                window.parent._showtab('xm_i' + data.id, '基本信息-' + data.projectName, '/supervisor/projectManager/projectInfor?type=m&id=' + data.id);
            }else if(obj.event==='export'){
                parent.layer.confirm('确定要导出所有的监理文档？', function (index) {
                    parent.layer.close(index);
                    window.location.href="/supervisor/projectManager/export?id="+data.id+'&name='+data.projectName;
                });
            }else if(obj.event==='modrecord'){
                //打开该项目的修改记录页面：
                var w = "";
                var h = "";
                if (w == null || w == '') {
                    w = ($(window).width() * 0.9);
                }
                ;
                if (h == null || h == '') {
                    h = ($(window).height() - 100);
                }
                layer.open({
                    type: 2,
                    area :  [w + 'px', h + 'px'],
                    maxmin: false,
                    title: false,
                    scrollbar: false,
                    shade: 0.8,
                    content: '/supervisor/projectManager/showProjectModRecord?pid='+data.id, //iframe的url，no代表不显示滚动条
                });
            }
        });
        // 监听排序 解决 项目进度排序后不显示的问题
        table.on('sort(project)', function (obj) {
            //遍历设置目前的宽度：
            saveTableWidth();
            table.reload('projectList', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    field: obj.field,//排序字段
                    order: obj.type//排序方式
                },
                cols: tableCols
            });
        });
    });

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#totalDurationBeginDate' //指定元素
        });
        laydate.render({
            elem: '#totalDurationEndDate' //指定元素
        });
    });

    function showDetail(id, projectName) {
        window.parent._showtab('xm_v' + id, '查看-' +projectName, '/supervisor/projectManager/projectDetail?type=v&id=' +id);
    }



    function getCity() {
        var code = $('#province option:selected').val();
        if (code == "") {
            return;
        }
        var code = code.replace(",", "");
        layerAjaxGet("/sys/register/getCity",{"code": code},'',function (data) {
            $("#city").empty();
            $("#city").append("<option value=''>选择市</option>");
            /*                var jsonData = JSON.parse(data);



                            alert(valData);*/
            var valData = data.data;
            for (var i = 0; i < valData.length; i++) {
                $("#city").append("<option value='" + valData[i].code + "'>" + valData[i].name + "</option>");
            }
        })



    }
    function reset(){
        $('#status').val("");
        $('#province').val("");
        $('#city').val("");
        $('#hyType').val("");
        $('#totalDurationBeginDate').val("");
        $('#totalDurationEndDate').val("");
        $('#htMoneyMin').val("");
        $('#htMoneyMax').val("");
        $('#projectOwner').val("");
        $('#projectName').val("");
        $('#insideContractNo').val("");
        var jsondata={
            status: "",
            province: "",
            city: "",
            hyType: "",
            createBy: "",
            startDate: "",
            endDate: "",
            htMoneyMin: "",
            htMoneyMax: "",
            projectOwner: "",
            projectName: "",
            insideContractNo: ""
        };
        saveTableWidth();
        table.reload('projectList', {where: jsondata,cols: tableCols});
    }

    function resiztProjectTable(){
        table.resize('projectList');
    }

    function query(a) {
        var status = $('#status').val();
        var province = $('#province').val();
        if (province != "") {
            province = province.replace(",", "")
        }
        var city = $('#city').val();
        if (city != "") {
            city = city.replace(",", "")
        }
        var hyType = $('#hyType').val();
        var startDate = $('#totalDurationBeginDate').val();
        var endDate = $('#totalDurationEndDate').val();
        var htMoneyMin = $('#htMoneyMin').val();
        var htMoneyMax = $('#htMoneyMax').val();
        var projectOwner = $('#projectOwner').val();
        var projectName = $('#projectName').val();
        var insideContractNo = $('#insideContractNo').val();
        var jsondata = {
            status: status,
            province: province,
            city: city,
            hyType: hyType,
            startDate: startDate,
            endDate: endDate,
            htMoneyMin: htMoneyMin,
            htMoneyMax: htMoneyMax,
            projectOwner: projectOwner,
            projectName: projectName,
            insideContractNo: insideContractNo,
        };
        // debugger;
        if (a) {
            jsondata.createBy = '${currentUser.id}';
        }else{
            jsondata.createBy='';
        }
        saveTableWidth();
        table.reload('projectList', {where: jsondata,cols: tableCols});
    }


    /*
*
*  查看项目详情
* */
    function viewDetail(id) {
        var w = ($(window).width() * 0.9);
        var h = ($(window).height() - 50);
        layer.open({
            id: 'user-update',
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: "项目详情",
            content: '/supervisor/projectManager/projectDetail?id=' + id
            , end: function () {
                tableIns.reload();
            }
        });

    }

    /*
    *
    * 回收站 查询
    * */
    function viewHs() {
        window.parent._showtab('xm_v_viewHS', '项目回收站', '/supervisor/projectManager/viewHs');
    }

    /*
    *
    * 账号信息查询
    * */
    function viewAc() {
        var checkStatus = table.checkStatus('projectList');
        var data = checkStatus.data;
        if (data.length == 0  || data.length>1) {
            layer.msg('请选择一条项目查看。', {icon: 5});
            return false;
        }else{
           var projectId= checkStatus.data[0].id;
           console.log(projectId);
            window.parent._showtab('xm_v_viewAc', '账号信息查询', '/supervisor/projectManager/viewAc?projectId='+projectId);
        }
    }

    /**
     * 回收站
     * */
    function deleteHs(id) {
        var checkStatus = table.checkStatus('projectList');
        var data = checkStatus.data;
        //获取选中数量
        var selectCount = checkStatus.data.length;
        if (data.length == 0) {
            layer.msg('请选择项目进行删除。', {icon: 5});
            return false;
        } else {
            var proNames = [];
            for (var i = 0; i < selectCount; i++) {
                proNames.push(checkStatus.data[i].projectName);
            }
            layer.confirm('确定将 '+proNames+' 项目放入回收站？', function (index) {
                var ids = [];
                for (var i = 0; i < selectCount; i++) {
                    ids.push(checkStatus.data[i].id);
                }
                var ids = ids.join(',');
                layerAjax("deleteHs", {ids: ids}, "", function (d) {
                    if (d.flag) {
                        layer.msg("操作成功", {icon: 1});
                        tableIns.reload();
                    } else {
                        layer.msg("操作失败", {icon: 2});
                    }
                })
            });
        }
    }

    /**
     * 回收站
     * */
    function deleteItem(id,projectName) {
        if (id) {
            layer.confirm('确定将'+projectName+'项目放入回收站？', function (index) {
                layerAjax("deleteHs", {ids: [id]}, "", function (d) {
                    if (d.flag) {
                        layer.msg("操作成功", {icon: 1});
                        tableIns.reload();
                    } else {
                        layer.msg("操作失败", {icon: 2});
                    }
                })
            });
        } else {
            layer.msg('请选择项目放入回收站', {icon: 5});
        }
    }

    function saveTableWidth(){
        //把表格的宽度设置到数组里面：
        var theTable = $(".layui-table")[0];
        var theThs = $(theTable).find('th');
        $.each(theThs,function(ind,e){
            if(ind > 6){
                return false;
            }
            tableCols[0][ind].width = $(e)[0].clientWidth;
        })
    }

</script>

<script type="text/html" id="shbz">
    {{#  if(d.shbz == '0'){ }}
    停用
    {{#  } else if(d.shbz == '1'){ }}
    正常
    {{#  } else{ }}
    '
    <div class="layui-progress layui-progress-big" lay-showpercent="true">
        <div class="layui-progress-bar layui-bg-orange" lay-percent="222%">111111</div>
    </div><br>'

    {{#  }  }}

</script>


<script type="text/html" id="zt">
    {{#  if(d.status == '000'){ }}
    已删除
    {{#  } else if(d.status == '001'){ }}
    未提交
    {{#  } else if(d.status == '002'){ }}
    未启动
    {{#  } else if(d.status == '004'){ }}
    进行中
    {{#  } else if(d.status == '003'){ }}
    已完成
    {{#  } else if(d.status == '005'){ }}
    未已延期
    {{#  } }}
</script>

</body>

</html>
